<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/jsp/comm_css_include.jsp"%>
<!-- zTreeStyle.css -->
<link rel="stylesheet" type="text/css" href="${basePath}/css/zTreeStyle/zTreeStyle/zTreeStyle.css">
<!doctype html>
<html>
<head>
	<style type="text/css">
	   .gray-bg
	   {
	     background-color: #fff;
	   }
	</style>
</head>
<body class="gray-bg">
	 <div class="ibox-content">
		<form class="form-horizontal m-t" id="commentForm">
			<table cellpadding="0" cellspacing="0" border="0" bordercolor="#3B95C8"  width="100%" class="tablefont">
				<tr>
				    <td width="23%" align="right">
				    	<label class="col-sm-3 control-label rp">所属公司：</label>
				    </td>
					<td width="75%">
						<div class="form-group">
		    				<select id="companyCode" name="companyCode" class="select-control"></select>
	    				</div>
					</td>
				</tr>
				
				<tr>
					<td width="23%" align="right">
						<label class="col-sm-3 control-label rp">父级节点：</label>
					</td>
					<td  width="75%">
						<div class="form-group">		
	    					<input id="id" name="id" type="hidden">
	    					<input id="parentId" name="parentId" type="hidden">
	    					<input id="parentName" name="parentName"  type="text" class="form-control smalliconcur smallicon" onclick="parentNamecho()" readonly="readonly"  aria-required="true" >
		    			</div>	
					</td>
				</tr>	
			
				<tr>
				    <td width="25%" align="right">
				    	<label class="col-sm-3 control-label np">菜单名称：</label>
				    </td>
					<td width="75%">
						<div class="form-group">
	    					<input id="menuName" name="menuName"  type="text" class="form-control" aria-required="true" required="required"   minlength="1" maxlength="64" placeholder="请输入菜单名称(必填)" />
	    				</div>
					</td>
				</tr>
				
				<tr>
				    <td width="23%" align="right">
				    	<label class="col-sm-3 control-label rp">菜单代码：</label>
				    </td>
					<td width="75%">
						<div class="form-group">
	    					<input id="menuCode" name="menuCode" readonly="readonly" type="text" class="form-control" aria-required="true" required="required"  minlength="1" maxlength="64" placeholder="请输入菜单代码(必填)">
	    				</div>
					</td>
				</tr>
				
				<tr>
					<td width="23%" align="right">
						<label class="col-sm-3 control-label rp">菜单排序：</label>
					</td>
					<td  width="75%">
						<div class="form-group">		
	    					<input id="sortValue" name="sortValue" minlength="1" min="1" maxlength="11" type="number" class="form-control" required="required" placeholder="菜单排序(必填)" >
		    			</div>	
					</td>
				</tr>
				<tr>
				    <td width="23%" align="right">
				    	<label class="col-sm-3 control-label np">备注：</label>
				    </td>
					<td width="75%">
						<div class="form-group">
		    				<textarea id="remarks" name="remarks" cols="20" rows="1" type="text" class="form-control" aria-required="true" placeholder="请输入备注" ></textarea>
	    				</div>
					</td>
				</tr>
			</table>
			<table cellpadding="0" cellspacing="0" border="0" bordercolor="#3B95C8"  width="100%">
				<tr>
					<td width="100%" align="center">
						 <div class="ibox-content">
				              <button type="button" class="btn dpbtn_green" onclick="Updatesave();">确定</button>
				              <button type="button" class="btn dpbtn_red" onclick="Reset();">重置</button>
				          </div>
					</td>
				</tr>
			</table>
		</form>
	</div>
	<!-- public quote -->
    <%@include file="/jsp/comm_js_include.jsp"%>

 	<!-- custom js -->
    
    <script type="text/javascript"></script>
    
    <!--zTreeStyle.js-->
	<script type="text/javascript" src="${basePath}/js/zTreeStyle/jquery.ztree.core.js" charset="utf-8"></script>
	<script type="text/javascript" src="${basePath}/js/zTreeStyle/jquery.ztree.excheck.js" charset="utf-8"></script>
    
    <!--
    	作者：zhangpp
    	时间：2017-04-06
    	描述：js
    -->
    <script type="text/javascript">  
  		$(function(){
  			var parentId = $.getUrlData("parentId");
  			var parentName = $.getUrlData("parentName");
  			$('#parentId').val(parentId);
  			$('#parentName').val(parentName);
  			
  			var id = $.getUrlData("id");
  			$('#id').val(id);
  			
  			$.dpAjax({
	    		url:'${basePath}/appMenu/getById',
    			data:{
    				"id":id,
    			},
    			success: function(datas){
    				   var result = datas.result;
					   var companyCode = result.companyCode;
					   companyChoose(companyCode);
					   $('#id').val(result.replaceId);
					   $('#menuName').val(result.menuName);
					   $('#menuCode').val(result.menuCode);
					   $('#remarks').val(result.remarks);
					   $('#sortValue').val(result.sortValue);
					   return;
                }
	    	});
  		});
  		
  		function companyChoose(companyCode){
	    	  $.dpAjax({
	    		    show:false,
	    	    	url:'${basePath}/DataDictionaryController/getEnableList',
	     			data:{"parentValue":"Company"},
	     			success: function(datas){
	     			  var result = datas.result.rows;
	  				  var html="";
	  			      for(var i=0;i<result.length;i++){
	  			          var programme = result[i];
	  			          html += '<option value="'+programme.value+'">'+programme.name+'</option>';
	  			      }
	  			      $("#companyCode").html(html);
	  			      $("#companyCode").val(companyCode);
	               }
	    	   });
	      } 
  		
  		var parentNamecho = function() {
   				 var content = '<div class="ibox-content" style="height: 300px;border: 1px solid #F5F5F6; overflow:auto;overflow-x: hidden;">'
   					+ '	<div id="treeDemo" class="ztree">&nbsp;</div>'
    				+ '</div>'
    				+ '<div class="ibox-content">'
    				+ '	 <button class="btn dpbtn_green" type="button" onclick="confirmRole();">确定</button>'
    				+ '	 <button class="btn dpbtn_red" type="button" onclick="cancelRole();">取消</button>'
    				+ '</div>';
     		
   		    	var UpdateIndex = layer.open({
   			    	  title:'菜单',
   			    	  type: 1,
   			    	  area: ['300px', '400px'], //宽高
   			    	  content: content
   			    });
   		    	var setting = {
   	 					check: {
   	 						enable: false
   	 					},
   	 					data: {
   	 						simpleData: {
   	 							enable: true
   	 						}
   	 					}
   	 			};
    		  $.fn.zTree.init($("#treeDemo"), setting, parent.getPowerList);
	    }
  		
  		var confirmRole = function()
	    {
	    	 var zTree = $.fn.zTree.getZTreeObj("treeDemo"); 
	    	 var node=zTree.getSelectedNodes();
	    	 var treeNode = node[0];
	    	 if(treeNode.id == $.getUrlData("id")) {
	    		 layer.msg('父节点不能为本身',{icon:7});
				 return;
	    	 }
	    	 var parentNode = treeNode.getParentNode();
	    	 document.getElementById('parentName').value=treeNode.name;
	    	 document.getElementById('parentId').value=treeNode.id;
	    	 layer.closeAll(); 
	    }
		function cancelRole() {
			layer.closeAll();
		}  		
  		//重置
  		var Reset = function(){
			document.getElementById('companyCode').value = "dp";
			document.getElementById('menuName').value = "";
			document.getElementById('sortValue').value = "";
			document.getElementById('remarks').value = "";
		}
  		
  	    var Updatesave = function()
  		{
  			var validstatus = $("#commentForm").valid();
  	    	if(validstatus)
  	    	{
  	    		var data = $('#commentForm').serialize();
  	    		layer.confirm('您确认要修改吗？', {
  		  			  btn: ['确定','取消'] //按钮
  				},function(){
  					layer.closeAll();
  					$.dpAjax({
      	 	    		url:'${basePath}/appMenu/modify',
      	     			data:data,
      	     			success: function(datas){
      	     			 	  layer.msg("修改成功！", {icon: 6});
	     				 	  parent.layer.close(parent.updatelayer);
	 						  return;
      	                 }
      	 	    	});
  					   					
  				});
  	    	}
  		} 
  	    
  	  $(function(){
			 $("#commentForm").validate({
			    rules: {
			    	sortValue: {
		            	zhengZS: true,
		            },
		        },
		        //重写showErrors
		        showErrors: function (errorMap, errorList) {
		            
		            $.each(errorList, function (i, v) {
		                layer.tips(v.message, v.element, { time: 1500 });
		                return false;
		            });  
		        },
		        /* 失去焦点时验证 */
		        onfocusout: function(element) { $(element).valid(); },
		        /*  键盘抬起不验证 */
		        onkeyup:false,
			 });
	 	})
    </script>
</body>
</html>
